/**
 * Created by oneminute on 7/17/14.
 */

var lz = require("../lib/utils/modules")();

exports.get = function (_req, _res, _opts, _callback) {
    var suid = lz.Utils.decrypt(_opts.suid);
    var page = _opts.p * lz.Config.webServer.page;

    var user = new lz.User({id: suid});
    user.load({method: "byId"}, function (err, _user) {
        if (_user) {
            lz.Utils.getSubList(page, _user.demands, function (_items, _isEnd) {
                var demands = [];
                _items.forEach (function(_demand) {
                    demands.push(_demand.getInfo('t'));
                });
                _callback(null, null, demands, _isEnd);
            });
        } else {
            // 用户店铺已停止运营
            _callback(lz.Config.errors.getError(lz.Config.errors.REQUEST_TEMPUSER_ERROR));
        }
    });
};
